
#include <ctype.h>
#include <stdlib.h>

#include "MonteCarloPi.h"
#include "GaussLegendre.h"
#include "Borwein.h"

#include "PiUtil.h"

int strcmp(const char *a, const char *b);

int strcmp(const char *a, const char *b)
{
	if (! (*a | *b)) return 0;
	return (*a != *b) ? *a-*b : strcmp(++a, ++b);
}

int main(int argc, char *argv[])
{
	pi_type pi;
	char *method = NULL;
	int threads = 1;


	mpf_set_default_prec(33219281);
	mpf_init(pi);


	// Treating arguments
	if(argc > 1)
		method = argv[1];
	if(argc > 2)
		threads = atoi(argv[2]);


	// No method provided
	if( method == NULL )
	{
		printf("Gimme a method!\n");
	}

	// Run Gaus Legandre
	else if( !strcmp(method, "GaussLegendre") )
	{
		if(threads <= 1)
			GaussLegendre_Sequencial(GL_ITERATIONS, &pi);
		else
			GaussLegendre_Paralelo(GL_ITERATIONS, &pi);

		gmp_printf("%.6Ff\n", pi);
	}

	// Run Borwein
	else if( !strcmp(method, "Borwein") )
	{
		if(threads <= 1)
			Borwein_Sequencial(GL_ITERATIONS, &pi);
		else
			Borwein_Paralelo(GL_ITERATIONS, &pi);

		gmp_printf("%.6Ff\n", pi);
	}

	// Run MonteCarlo
	else if( !strcmp(method, "MonteCarlo") )
	{
		double dPi = MonteCarloPi(MC_ITERATIONS, threads);
		printf("%.6lf\n", dPi);
	}

	mpf_clear(pi);

	return 0;
}